﻿@{
    ViewBag.Title = "Form"; 
    Layout = "~/Views/Shared/_Form.cshtml";
}
<script>
    layui.use(['jquery', 'form', 'upload', 'common','optimizeSelectOption'], function () {
        var form = layui.form,
            $ = layui.$,
            common = layui.common,
            upload = layui.upload;
        var keyValue = $.request("keyValue");
        //权限字段
        common.authorizeFields('adminform');
        var printTemplateJson ='';
        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            , url: '/FileManage/Uploadfile/Upload' //改成您自己的上传接口
            , size: 10240
            , accept: 'file'
            , data: { filetype: 4, fileby: '报表模板' }
            , before: function (obj) {
                //预读本地文件示例，不支持ie8 
                obj.preview(function (index, file, result) {
                    parentPage.window.importFile(file);
                });
            }
            , done: function (res) {
                //如果上传失败
                if (res.code > 0) {
                    //失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                    common.modalMsg(res.msg, "warning");
                    return false;
                }
                $("#F_PrintTemplatePath").val(res.data[0].src);
                printTemplateJson = parentPage.window.exportToJSONText();
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });
        $(function () {
            initControl();
            if (!!keyValue) {
                 common.ajax({
                     url: '/SystemManage/ReportTemplate/GetFormJson',
                   dataType: 'json',
                   data: { keyValue: keyValue },
                   async: false,
                   success: function (data) {
                       common.val('adminform', data);
                    }
               });
           }
           form.render();
       });
       wcLoading.close();

       function initControl() {
           //此处需修改
           //绑定数据源
           //类型为下拉框时
       }
        
       //监听提交
       form.on('submit(saveBtn)', function (data) {
           var postData = data.field;
           postData.F_PrintTemplateJson = printTemplateJson;
           if (!postData["F_EnabledMark"]) postData["F_EnabledMark"] = false;
           common.submitForm({
               url: '/SystemManage/ReportTemplate/SubmitForm?keyValue=' + keyValue,
               param: postData,
               success: function () {
                   common.parentreload('data-search-btn');
               }
           })
           return false;
       });
   });
</script>

<body>
    <div class="layuimini-container">
        <div class="layuimini-main">
            <div class="layui-form layuimini-form" lay-filter="adminform">
                <div class="layui-form-item layui-hide">
                    <label class="layui-form-label required">模板名称</label>
                    <div class="layui-input-block">
                        <input type="text" id="F_PrintTemplateName" name="F_PrintTemplateName" autocomplete="off" maxlength="50" lay-verify="required" placeholder="请输入模板名称" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-hide">
                    <label class="layui-form-label required">模板地址</label>
                    <div class="layui-input-block" style="padding-right: 100px;">
                        <input type="text" id="F_PrintTemplatePath" name="F_PrintTemplatePath" lay-verify="required" readonly class="layui-input">
                        <button type="button" class="layui-btn" id="test1" style="position: absolute;top: 0;right: 6px;cursor: pointer;">上传模板</button>
                    </div>
                </div>
                <div class="layui-form-item layui-form-text layui-hide">
                    <label class="layui-form-label required">模板类型</label>
                    <div class="layui-input-block">
                        <select id="F_PrintTemplateType" name="F_PrintTemplateType" lay-verify="required" lay-search>
                            <option value="0">json文件</option>
                            <option value="1" selected>xlsx文件</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item layui-hide">
                    <label class="layui-form-label">选项</label>
                    <div class="layui-input-block">
                        <input type="checkbox" name="F_EnabledMark" id="F_EnabledMark" checked="" value="true" title="有效标识">
                    </div>
                </div>
                <div class="layui-hide">
                    <iframe src="../../spreadjs/index.html" width="100%" height="600px" name="parentPage">
                    </iframe>
                </div>
                <div class="layui-form-item layui-form-text layui-hide">
                    <label class="layui-form-label">备注</label>
                    <div class="layui-input-block">
                        <textarea id="F_Description" name="F_Description" class="layui-textarea" placeholder="请输入备注"></textarea>
                    </div>
                </div>
                <div class="layui-form-item layui-hide">
                    <button class="layui-btn site-demo-active" lay-submit id="submit" lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </div>
    </div>
</body>

